<?php

class Zend_View_Helper_ItemImg
{
    protected $urls = null;
    
    protected $classes = array(
        'small' => 'item_icon_small',
        'medium' => 'item_icon_medium',
        'large' => 'item_icon_large',
    );
    
	function itemImg($image, $size = 'medium') 
	{
	    if (!$this->urls) {
	        $config = Zend_Registry::getInstance()->configuration;
            
            $iconsSmall = isset($config->wowhead->images->items->small) ? $config->wowhead->images->items->small : null;
            $iconsMedium = isset($config->wowhead->images->items->medium) ? $config->wowhead->images->items->medium : null;
            $iconsLarge = isset($config->wowhead->images->items->large) ? $config->wowhead->images->items->large : null;
            
            if (!$iconsSmall) {
                throw new Exception('Wowhead small items icons url not defined in config.');
            }
            
	        if (!$iconsMedium) {
                throw new Exception('Wowhead medium items icons url not defined in config.');
            }
            
	        if (!$iconsLarge) {
                throw new Exception('Wowhead large items icons url not defined in config.');
            }
            
            $this->urls = array(
                'small' => $iconsSmall,
                'medium' => $iconsMedium,
                'large' => $iconsLarge,
            );
	    }
	    
	    if (!array_key_exists($size, $this->urls)) {
	        $size = 'medium';
	    }
	    
	    // TODO: Should check if the image has a extension and remove it
	    
		$url = $this->urls[$size] . $image . ".jpg";
		/*
		$result  = '<div class="' .$this->classes[$size]. '">';
		$result .= '<div style="background-image: url(' . $url . ');"/>';
		$result .= '</div>';
		return $result;
        */
		
		return '<img src="'. $url .'"/>';
	}
	
	
}